<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.ico?v=5.1.4">


  <link rel="mask-icon" href="/images/facicon.ico?v=5.1.4" color="#222">





  <meta name="keywords" content="Linux,Shell,">





  <link rel="alternate" href="/atom.xml" title="Key" type="application/atom+xml">






<meta name="description" content="注释单行注释用   #    注释 多行注释:前面加  :&amp;lt;&amp;lt;!   后面加  ! expr运算代码: 1234567a=10b=2sum=`expr $a + $b`   #加法    反引号用来引用语句执行结果min=`expr $a - $b`   #减法mul=`expr $a \* $b` #乘法div=`expr $a / $b` #除法yu=`expr $a % $b`">
<meta name="keywords" content="Linux,Shell">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux Shell脚本-2">
<meta property="og:url" content="https://blog.qipo.net/2017/06/27/bashshell/index.html">
<meta property="og:site_name" content="Key">
<meta property="og:description" content="注释单行注释用   #    注释 多行注释:前面加  :&amp;lt;&amp;lt;!   后面加  ! expr运算代码: 1234567a=10b=2sum=`expr $a + $b`   #加法    反引号用来引用语句执行结果min=`expr $a - $b`   #减法mul=`expr $a \* $b` #乘法div=`expr $a / $b` #除法yu=`expr $a % $b`">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-06-03T02:37:45.058Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux Shell脚本-2">
<meta name="twitter:description" content="注释单行注释用   #    注释 多行注释:前面加  :&amp;lt;&amp;lt;!   后面加  ! expr运算代码: 1234567a=10b=2sum=`expr $a + $b`   #加法    反引号用来引用语句执行结果min=`expr $a - $b`   #减法mul=`expr $a \* $b` #乘法div=`expr $a / $b` #除法yu=`expr $a % $b`">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://blog.qipo.net/2017/06/27/bashshell/">





  <title>Linux Shell脚本-2 | Key</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Key</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description"></h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://blog.qipo.net/2017/06/27/bashshell/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Key">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Key">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">Linux Shell脚本-2</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-27T17:14:54+08:00">
                2017-06-27
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Linux/" itemprop="url" rel="index">
                    <span itemprop="name">Linux</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.2k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  5
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h1><p>单行注释用   #    注释</p>
<p>多行注释:前面加  :&lt;&lt;!   后面加  !</p>
<h1 id="expr运算"><a href="#expr运算" class="headerlink" title="expr运算"></a>expr运算</h1><p>代码:</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">a</span>=<span class="number">10</span></span><br><span class="line"><span class="attr">b</span>=<span class="number">2</span></span><br><span class="line"><span class="attr">sum</span>=`expr <span class="variable">$a</span> + <span class="variable">$b</span>`   #加法    反引号用来引用语句执行结果</span><br><span class="line"><span class="attr">min</span>=`expr <span class="variable">$a</span> - <span class="variable">$b</span>`   #减法</span><br><span class="line"><span class="attr">mul</span>=`expr <span class="variable">$a</span> \* <span class="variable">$b</span>` #乘法</span><br><span class="line"><span class="attr">div</span>=`expr <span class="variable">$a</span> / <span class="variable">$b</span>` #除法</span><br><span class="line"><span class="attr">yu</span>=`expr <span class="variable">$a</span> % <span class="variable">$b</span>` #取余</span><br></pre></td></tr></table></figure>
<p>关于运算优先级,要加括号,不然只会先乘除后加减.括号必须如下加上  <code>\</code> 反义字符.还有表达式两边是    (反撇)  并不是 <code>&#39;</code> (引号).</p>
<p>deshu=<code>expr \( $a \* $b + $c  - $d \) / $b</code></p>
<h1 id="let运算"><a href="#let运算" class="headerlink" title="let运算"></a>let运算</h1><p>代码:</p>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">read <span class="selector-tag">a</span> b</span><br><span class="line">let <span class="string">" c = a * b "</span></span><br><span class="line">echo <span class="variable">$c</span></span><br></pre></td></tr></table></figure>
<p>let ：用来执行算数运算和数值表达式测试。</p>
<p>let 命令的替代表示形式是: ((算术表达式)) ，这样做的好处是如果表达式中含有特殊的字符，可以告示shell 进行特殊处理.</p>
<p>特点:</p>
<ol>
<li><p>在双括号结构中，所有表达式可以像c语言一样，如：a++,b–等。</p>
</li>
<li><p>在双括号结构中，所有变量可以不加入：“$”符号前缀。</p>
</li>
<li><p>双括号可以进行逻辑运算，四则运算</p>
</li>
<li><p>双括号结构 扩展了for，while,if条件测试运算</p>
</li>
<li><p>支持多个表达式运算，各个表达式之间用“，”分开</p>
</li>
</ol>
<h1 id="逻辑判断语句"><a href="#逻辑判断语句" class="headerlink" title="逻辑判断语句"></a>逻辑判断语句</h1><p>代码:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> <span class="built_in">test</span> 4 -gt 3                     <span class="comment">#也可以用   if [ 4 -gt 3 ]              -gt :是前一个数如果大于后一个数,输出true</span></span><br><span class="line"><span class="keyword">then</span>  <span class="built_in">echo</span> <span class="string">"4 大于 3"</span></span><br><span class="line"><span class="keyword">fi</span></span><br></pre></td></tr></table></figure>
<p>必须用  if   倒过来结尾即:   fi</p>
<p> 1）判断表达式</p>
<ul>
<li><p>if test     (表达式为真)</p>
</li>
<li><p>if !test     !表达式为假</p>
</li>
<li><p>test 表达式1 –a 表达式2                  两个表达式都为真</p>
</li>
<li><p>test 表达式1 –o 表达式2                 两个表达式有一个为真</p>
</li>
</ul>
<p>2）判断字符串</p>
<ul>
<li><p>test –n 字符串                                   字符串的长度非零</p>
</li>
<li><p>test –z 字符串                                    字符串的长度为零</p>
</li>
<li><p>test 字符串1＝字符串2                    字符串相等</p>
</li>
<li><p>test 字符串1 !＝ 字符串2               字符串不等</p>
</li>
</ul>
<p>3）判断整数</p>
<ul>
<li><p>test 整数1 –eq 整数2                        整数相等</p>
</li>
<li><p>test 整数1 –ge 整数2                        整数1大于等于整数2</p>
</li>
<li><p>test 整数1 –gt 整数2                         整数1大于整数2</p>
</li>
<li><p>test 整数1 –le 整数2                         整数1小于等于整数2</p>
</li>
<li><p>test 整数1 –lt 整数2                          整数1小于整数2</p>
</li>
<li><p>test 整数1 –ne 整数2                        整数1不等于整数2</p>
</li>
</ul>
<p>4）判断文件</p>
<ul>
<li><p>test  File1 –nt  File2　　　　　　　　文件1比文件2 新</p>
</li>
<li><p>test  File1 –ot  File2　　　　　　　　文件1比文件2 旧</p>
</li>
<li><p>test –d File　　　　　　　　文件存在并且是目录</p>
</li>
<li><p>test –f File 　　　　　　　 文件存在并且是正规文件</p>
</li>
<li><p>test –e File　　　　　　　　文件存在</p>
</li>
<li>test –r File　　　　　　　　文件存在并且可读</li>
<li><p>test –w File　　　　　　　　文件存在并且可写</p>
</li>
<li><p>test –x File　　　　　　　　文件存在并且可执行</p>
</li>
<li><p>test  File1 –ef  File2　　　　　　　　两个文件具有同样的设备号和i结点号</p>
</li>
</ul>
<ul>
<li><p>test –b File　　　　　　　　文件存在并且是块设备文件</p>
</li>
<li><p>test –c File　　　　　　　　文件存在并且是字符设备文件</p>
</li>
<li><p>test –g File　　　　　　　　文件存在并且是设置了组ID</p>
</li>
<li><p>test –G File　　　　　　　　文件存在并且属于有效组I</p>
</li>
<li><p>test –h File　　　　　　　　文件存在并且是一个符号链接（同-L）</p>
</li>
<li><p>test –k File　　　　　　　　文件存在并且设置了sticky位</p>
</li>
<li><p>test –b File　　　　　　　　文件存在并且是块设备文件</p>
</li>
<li><p>test –L File　　　　　　　　文件存在并且是一个符号链接（同-h）</p>
</li>
<li><p>test –o File　　　　　　　　文件存在并且属于有效用户ID</p>
</li>
<li><p>test –p File　　　　　　　　文件存在并且是一个命名管道</p>
</li>
<li><p>test –s File　　　　　　　　文件存在并且是一个套接字</p>
</li>
<li><p>test –t FD　　　　　　　　  文件描述符是在一个终端打开的</p>
</li>
<li><p>test –u File　　　　　　　　文件存在并且设置了它的set-user-id位</p>
</li>
</ul>
<p>if_else语句:</p>
<p>代码:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"><span class="keyword">if</span> [ <span class="variable">$#</span> -ne 1 ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">  <span class="built_in">exit</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"><span class="keyword">if</span> ! [ -e <span class="variable">$1</span> ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">  <span class="built_in">exit</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"><span class="keyword">if</span> [ -d <span class="variable">$1</span> ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"该文件是个目录"</span></span><br><span class="line"><span class="keyword">elif</span> [ -f <span class="variable">$1</span> ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"该文件是个普通文件"</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"该文件是个其他类型的文件"</span></span><br><span class="line"><span class="keyword">fi</span></span><br></pre></td></tr></table></figure>
<h1 id="练习"><a href="#练习" class="headerlink" title="练习"></a>练习</h1><ol>
<li><p>在家目录下创建一个文件夹 dir,在此文件夹中创建一个文件, if_file判断这个文件是否创建成功并打印这个文件的读写执行权限.</p>
</li>
<li><p>当前系统时间,判断是闰年还是平年.</p>
</li>
</ol>
<h1 id="答案"><a href="#答案" class="headerlink" title="答案"></a>答案</h1><h2 id="1-代码"><a href="#1-代码" class="headerlink" title="1.代码:"></a>1.代码:</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span></span><br><span class="line">mkdir dir</span><br><span class="line"><span class="built_in">cd</span> dir</span><br><span class="line">touch if_file</span><br><span class="line"><span class="keyword">if</span> [ -e if_file ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"创建成功!"</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"><span class="keyword">if</span> [ -r if_file ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"可读"</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"不可读"</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"><span class="keyword">if</span> [ -w if_file ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"可写"</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"不可读"</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"><span class="keyword">if</span> [ -x if_file ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"可执行"</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"不可执行"</span></span><br><span class="line"><span class="keyword">fi</span></span><br></pre></td></tr></table></figure>
<h2 id="2-代码"><a href="#2-代码" class="headerlink" title="2.代码:"></a>2.代码:</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">DATE=`date`</span><br><span class="line">y=<span class="variable">$&#123;DATE:0:4&#125;</span></span><br><span class="line"><span class="built_in">echo</span> <span class="variable">$y</span></span><br><span class="line"><span class="built_in">let</span> <span class="string">"nl = y % 4 "</span></span><br><span class="line"><span class="built_in">let</span> <span class="string">"nw = y % 100"</span></span><br><span class="line"><span class="built_in">let</span> <span class="string">"nc = y % 400"</span></span><br><span class="line"><span class="keyword">if</span> [ <span class="variable">$nl</span> -eq 0 -a <span class="variable">$nw</span> -ne 0 ] || [ <span class="variable">$nc</span> -eq 0 ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"是闰年"</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"不是闰年"</span></span><br><span class="line"><span class="keyword">fi</span></span><br></pre></td></tr></table></figure>
<h1 id="小数运算"><a href="#小数运算" class="headerlink" title="小数运算"></a>小数运算</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">value = `<span class="built_in">echo</span> <span class="string">"1.1 + 2.2"</span> | bc`</span><br><span class="line"><span class="built_in">echo</span> <span class="variable">$value</span></span><br></pre></td></tr></table></figure>
<h1 id="case语句"><a href="#case语句" class="headerlink" title="case语句"></a>case语句</h1><p>比如:输入一个成绩,根据分数给出ABCD评级</p>
<p>代码如下:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"><span class="built_in">read</span> i</span><br><span class="line"><span class="keyword">if</span> [ <span class="variable">$i</span> -gt 100 -o <span class="variable">$i</span>  -lt  0 ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">"您输入的不是成绩吧,你妈的,好好输"</span></span><br><span class="line">  <span class="built_in">exit</span> 1</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">  <span class="built_in">let</span> <span class="string">" g = <span class="variable">$i</span> / 10 "</span></span><br><span class="line">  <span class="keyword">case</span> <span class="variable">$g</span> <span class="keyword">in</span></span><br><span class="line">    9 | 10 )             <span class="comment">#用 | 可以添加多个常量</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"A"</span></span><br><span class="line">    ;;                    <span class="comment">#语句结束必须;;结尾</span></span><br><span class="line">    8 )</span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"B"</span></span><br><span class="line">    ;;</span><br><span class="line">    7 )</span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"C"</span></span><br><span class="line">    ;;</span><br><span class="line">    * )                  <span class="comment"># 这就是其他</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"D"</span></span><br><span class="line">  <span class="keyword">esac</span>           <span class="comment"># case反过来结尾,即:esac</span></span><br><span class="line"><span class="keyword">fi</span></span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="Key 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="Key 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux/" rel="tag"># Linux</a>
          
            <a href="/tags/Shell/" rel="tag"># Shell</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/06/26/shell/" rel="next" title="Linux Shell脚本">
                <i class="fa fa-chevron-left"></i> Linux Shell脚本
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/06/28/shell/" rel="prev" title="Linux Shell脚本-3">
                Linux Shell脚本-3 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="Key">
            
              <p class="site-author-name" itemprop="name">Key</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">107</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">28</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/keyarea" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:wxkayle@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#注释"><span class="nav-number">1.</span> <span class="nav-text">注释</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#expr运算"><span class="nav-number">2.</span> <span class="nav-text">expr运算</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#let运算"><span class="nav-number">3.</span> <span class="nav-text">let运算</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#逻辑判断语句"><span class="nav-number">4.</span> <span class="nav-text">逻辑判断语句</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#练习"><span class="nav-number">5.</span> <span class="nav-text">练习</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#答案"><span class="nav-number">6.</span> <span class="nav-text">答案</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-代码"><span class="nav-number">6.1.</span> <span class="nav-text">1.代码:</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-代码"><span class="nav-number">6.2.</span> <span class="nav-text">2.代码:</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#小数运算"><span class="nav-number">7.</span> <span class="nav-text">小数运算</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#case语句"><span class="nav-number">8.</span> <span class="nav-text">case语句</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-snowflake-o"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Key</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">190.8k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
